package com.laihui.adapter;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.laihui.activity.R;
import com.laihui.model.Invest;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;

import java.text.DecimalFormat;

/**
 * Created by ST on 2017/7/22.
 */

public class BorrowRecordAdapter extends RecyclerArrayAdapter<Invest.BorrowsBean> {
    public BorrowRecordAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent ,int viewType) {
        return new BorrowRecordViewHolder(parent);
    }


    class BorrowRecordViewHolder extends BaseViewHolder<Invest.BorrowsBean> {
        private TextView tv_loan_name,tv_loan_progress,tv_loan_money,borrow_last_money,tv_loan_apr,tv_time_limit;
        private ProgressBar pb;






        public BorrowRecordViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_invest_fragment);
            tv_loan_name = $(R.id.tv_loan_name);
            tv_time_limit = $(R.id.tv_time_limit);
            tv_loan_money = $(R.id.tv_loan_money);
            tv_loan_apr = $(R.id.tv_loan_apr);

            pb = $(R.id.tv_loan_progress);

        }

        @Override
        public void setData(Invest.BorrowsBean data) {

            DecimalFormat df = new DecimalFormat("0.00");
            tv_loan_name.setText(data.getName()+"");
            tv_loan_apr.setText(df.format(data.getApr())+"%");
            if (data.getIs_day()==1){
                tv_time_limit.setText(data.getTime_limit()+"天");
            }else{
                tv_time_limit.setText(data.getTime_limit()+"个月");
            }
            pb.setProgress(((int) (new Double(data.getAccount_yes() )/new Double( data.getAccount())*100)));
            //
            tv_loan_money.setText("总金额:"+data.getAccount());


            pb.setProgress((int) (((int) (new Double(data.getAccount_yes() )/new Double( data.getAccount())*100))));
            ObjectAnimator animator = ObjectAnimator.ofInt(pb, "progress", 0, ((int) (new Double(data.getAccount_yes() )/new Double( data.getAccount())*100)));
            animator.setDuration(3000);
            animator.start();
//



            super.setData(data);

        }
    }


}
